Results 1 to 6 of 6

Thread: Multiple Spawned static models in an array ??

  1. #1
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default Multiple Spawned static models in an array ??

    Hi

    Lets say you want to make steps out of crates to get somewhere right?
    In every mod ive seen you need to add heaps of these
    eg
    Code:
    local.static = spawn script_model
    	local.static model "static/indycrate.tik"
    	local.static.origin = ( 805 485 -140 )
    	local.static.angles = ( 0 90 0 )
    	local.static solid
    	local.static nodamage
    
    	local.static = spawn script_model
    	local.static model "static/indycrate.tik"
    	local.static.origin = ( 805 485 -92 )
    	local.static.angles = ( 0 90 0 )
    	local.static solid
    	local.static nodamage
    
    etc
    etc
    And so on just to make a few steps

    Now ive looked through some mods that use array to spawn flaks in different positions to blow up
    eg

    Code:
    ////------setup random spots for the flak---
    
    local.origins = makeArray
    ( -432.25 1078.15 23.56 )( 0 175 0 )
    ( -1560.30 -127.01 -22.43 )( 0 -95 0 )
    ( -1560.30 -127.01 -22.43 )( 0 -95 0 )
    ( 560.23 -66.56 -47.20 )( 0 -126 0 )
    endArray
        
    local.random = randomint(local.origins.size)+1
    
    local.random_coords = local.origins[local.random][1]
    local.random_angles = local.origins[local.random][2]
    
    thread flak local.random_coords local.random_angles
    
    
    flak local.origin local.angles:
    
    //local.angles = ( 0 local.angle 0 )
    local.x = (angles_toforward local.angles)
    local.y = (angles_toleft local.angles) * -1
    local.z = angles_toup local.angles
    
    local.flakbase = spawn script_model
    local.flakbase model "statweapons/flak88base.tik"
    local.flakbase.origin = local.origin
    local.flakbase.angles = local.angles
    local.flakbase.targetname = "flak88_base1"
    
    local.flakcoll1 = spawn script_model
    local.flakcoll1 model "items/dm_50_healthbox.tik"
    local.flakcoll1.origin = local.origin
    local.flakcoll1 setsize ( -100 -26 -50 ) ( 105 26 100 )
    local.flakcoll1.angles = local.angles
    local.flakcoll1 hide
    
    local.flakcoll2 = spawn script_model
    local.flakcoll2 model "items/dm_50_healthbox.tik"
    local.flakcoll2.origin = (local.origin + (local.x * 50))
    local.flakcoll2 setsize ( -15 -75 -50 ) ( 15 75 100 )
    local.flakcoll2.angles = local.angles
    local.flakcoll2 hide
    
    local.flak = spawn script_model
    local.flak model "statweapons/flak88turret.tik"
    local.flak.origin = (local.origin + (local.z * 48 ))
    local.flak.angles = local.angles
    local.flak.targetname = "flak88_weapon1"
    local.flak.destroyed_model = "models/statweapons/flak88_d.tik"
    
    local.bomb = spawn script_model
    local.bomb model "items/pulse_explosive.tik"
    local.bomb.origin = (local.origin + (local.x * 7.75) + (local.y * -35.78 ) + (local.z * 64.0))
    local.bomb.angles = local.angles
    local.bomb.targetname = "bomb1"
    local.bomb.explosion_sound = "grenade_explode"
    local.bomb.explosion_fx = "fx/fx_flak88_explosion.tik"
    local.bomb.trigger_name = "flak88_weapon1_trigger"
    local.bomb.target = "flak88_weapon1"
    
    local.trigger = spawn trigger_use
    local.trigger.targetname = "flak88_weapon1_trigger"
    local.trigger.origin = (local.origin + (local.x * -3.0) + (local.y * -30.0) + (local.z * 71.0))
    local.trigger setsize ( -10 -10 -10 ) ( 10 10 10 )
    local.trigger.angles = local.angles
    end
    Now ive tried unsuccessfully to use this method to spawn objects but not make them random and always be there.
    So you have something like


    Code:
    local.origins = makeArray
    ( -432.25 1078.15 23.56 )( 0 175 0 )
    ( -1560.30 -127.01 -22.43 )( 0 -95 0 )
    ( -1560.30 -127.01 -22.43 )( 0 -95 0 )
    ( 560.23 -66.56 -47.20 )( 0 -126 0 )
    endArray
    
    thread crate local.origin local.angles
    
    crate local.origin local.angles:
    
    //local.angles = ( 0 local.angle 0 )
    local.x = (angles_toforward local.angles)
    local.y = (angles_toleft local.angles) * -1
    local.z = angles_toup local.angles
    
            local.static = spawn script_model
    	local.static model "static/indycrate.tik"
    	local.static.origin = local.origin
    	local.static.angles = local.angles
    	local.static solid
    	local.static nodamage
    But it doesnt seem to work, tried changing just little bits of the mod above, but all ive managed to do it turn the flak into a crate with a bomb , but i just want normal crates in an easier format with an array for the coords instead of heaps of the same object in different spots
    I tried to explain it best i could , if it seems abit confusing ill try to explain clearer

    So if anyone has something like to to spawn the same object at multiple spots without typing in heaps it would be appreciated
    Last edited by Purple Elephant1au; September 5th, 2012 at 07:25 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  2. #2
    Über Prodigy & Developer Razo[R]apiD's Avatar
    Join Date
    May 2010
    Location
    Poland, Lublin
    Posts
    3,245

    Default

    You need to loop through the array don't you? Also you have a typo:

    thread crate local.origin local.angles, and your array is named local.origins

  3. #3
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hi

    I wouldnt no what you mean by looping the array , i just wrote that up from looking at the flak one above it , it should be simple enough to work , i dont no much about this type of stuff , i mainly look at examples and try and change them to suit what i need , i dont what part of it will or wont work, i am just really after a simple code that looks like that but works lol

    And the origins and origin typo , i just copied what the flak one used and that worked , but ive fixed it and nothing changed , any chance someone could just post an example of array used with spawning objects, ive seen them with teleports and bombs that move but not one just for objects, it will just make my map.scr look abit more tidy and easier to edit

    Thankyou

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  4. #4
    Über Prodigy & Developer Razo[R]apiD's Avatar
    Join Date
    May 2010
    Location
    Poland, Lublin
    Posts
    3,245

    Default

    You have to loop through each element of the array, array is like a bag of apples. If your brother or sister would be the function that takes only one apple at the time, you would need to iterate through the apples in a bag which means you would need to take one apple by one from the bag and hand it over to you brother. Your brother can't carry whole bag of apples bcause he's too young, so you take apple by apple from the bag and give it to him.

    So array is like a bag with items which are origin vectors. You have to iterate through every origin variable inside of the array and pass it to the function.

  5. #5
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    You can use a starting origin plus the number of steps you need to build your staircase of crates, although the method is efficient but convoluted.

    Basically, the starting origin is where the first crate is spawned. According to its angle & position you can spawn one above it (either you determine the height of the indycrate model or let a special script determine it for you) with a specified length away from it (using angles_toforward * dist which creates a stairs effect). You can keep doing that if you specify a height the staircase must reach or when you specify the number of crates to be used in the staircase. Either method requires the your script to accommodate it (in particular the for() loop that will handle the building). In this scenario, you will only need 1 origin. If this is what you want, I can write it for you later tonight, or possibly tomorrow at noon.

    However if you only mentioned this as an example, it becomes a lot more easy despite the fact that will need an array of origin vectors for your objects. In that case just do a makeArray of all your origin vectors (additionally you can add angles vectors as well, but remember they must be at least one space next to their respective origin vectors):
    Code:
    local.array = makeArray
    ( -432.25 1078.15 23.56 ) ( 0 175 0 )
    ( -1560.30 -127.01 -22.43 ) ( 0 -95 0 )
    ( -1560.30 -127.01 -22.43 ) ( 0 -95 0 )
    ( 560.23 -66.56 -47.20 ) ( 0 -126 0 )
    endArray
    Now for the for() loop that will spawn all of your objects with the appropriate origin and angles vectors. I'm using local. variables so the above code snippet and the following must be in the same thread.
    Code:
    for (local.i = 1; local.i <= local.array.size; local.i++) {
    	local.static = spawn script_model model "static/indycrate.tik"
    	local.static.origin = local.array[local.i][1]
    	local.static.angles = local.array[local.i][2]
    	local.static solid
    	local.static nodamage
    }
    Basically, a for() statement works like this. The code before the first semicolon(; ) establishes something before the loop begins. At the start of each loop, the middle statement is assessed, i.e. is local.i (being 1 here) smaller than or equal to the size of local.array (being 4 here), if yes then the loop will continue; if false, then the loop will break and the engine will immediately skip to behind the closing }-bracket and keeps on reading from there. At the end of each loop, the final statement (after the second semicolon(; )) is executed which (usually) increases local.i by 1. So the for() statement will loop 4 times because local.i will increase from 1 to 2, to 3, to 4 and to 5. When it's 5, the middle statement will be assessed as false and the loop will break before the 5th loop even begins.

    Now, local.i is important because a hasharray (this is the name of the array the command makeArray creates) is two-dimensional. The first dimension is where 'local.i' is used to determine the row (and there are 4 rows here) so it points to one origin vector with its corresponding angles in the second dimension (which kind of like determines the columns). We made sure both vectors are always on a fixed position (i.e. origin first, angles second) so no variable like 'local.i' is used for the second dimension. This means 'local.array.size' returns the number of entries in the first dimension (in other words, the amount of rows). Were we to determine the number of entries in the second dimension we need to use 'local.array[1].size' or 'local.array[local.i].size'. Hasharrays always start with their entries at 1, regardless of which dimension (in contrast to vector- and string-arrays which start at entry 0).

    I hope the following clarifies it better:
    local.array = 'type array'
    local.array.size = 4
    local.array[1] = 'type array'
    local.array[1].size = 2
    local.array[1][1] = ( -432.25 1078.15 23.56 )
    local.array[1][2] = ( 0 175 0 )
    local.array[1][1].size = 1 => That's right! For some silly reason, vector arrays (and ONLY vectors) are seen as 1 variable even though they're made up of 3 different values, but you can still access these values
    local.array[1][1][0] = -432.25 => vector and string arrays start at entry 0
    local.array[1][1][1] = 1078.15
    local.array[1][1][2] = 23.56
    local.array[2][1] = ( -1560.30 -127.01 -22.43 )
    local.array[2][2] = ( 0 -95 0 )
    local.array[3][1] = ( -1560.30 -127.01 -22.43 )
    local.array[3][2] = ( 0 -95 0 )
    local.array[4][1] = ( 560.23 -66.56 -47.20 )
    local.array[4][2] = ( 0 -126 0 )
    Oh, and also worth noting is that strings containing the filepath to the model you wish to spawn can also be inserted into this hasharray. This will allow you to use the same array and the same function to spawn different kinds of models at once:
    Code:
    local.array = makeArray
    "static/indycrate.tik" ( -432.25 1078.15 23.56 ) ( 0 175 0 )
    "fx/corona_red.tik" ( -1560.30 -127.01 -22.43 ) ( 0 -95 0 )
    "static/corona_reg.tik" ( -1560.30 -127.01 -22.43 ) ( 0 -95 0 )
    "static/indycrate.tik" ( 560.23 -66.56 -47.20 ) ( 0 -126 0 )
    endArray
    
    for (local.i = 1; local.i <= local.array.size; local.i++) {
    	local.static = spawn script_model model local.array[local.i][1]
    	local.static.origin = local.array[local.i][2]
    	local.static.angles = local.array[local.i][3]
    	local.static solid
    	local.static nodamage
    }
    Last edited by Sor; September 6th, 2012 at 07:26 AM.

  6. #6
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hello

    Thanks heaps guys , i understand it alot better now, and it works for what i need.
    Razor i dont quite get the apple analogy, but it makes a little sense after reading Sor's post.

    Thanks again guys

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •